package com.ricemall.product.web;

import com.ricemall.product.entity.CategoryEntity;
import com.ricemall.product.service.CategoryService;
import com.ricemall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author cappuccino
 * @Date 2021-06-10 20:27
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","index.html"})
    public String indexPage(Model model){

        List<CategoryEntity> categoryEntitys = categoryService.getLevel1Categorys();
        model.addAttribute("categorys",categoryEntitys);
        return "index";
    }

    @ResponseBody
    @RequestMapping("index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatlogJson(Model model) {
        Map<String, List<Catelog2Vo>> map = categoryService.getCatelogJson();
        model.addAttribute("categorys",map);
        return map;
    }

}
